package com.lyl.lawyer.controller;


import com.cn.lyl.lawyer.model.entity.UserModel;
import com.cn.lyl.lawyer.service.UserService;
import com.cn.lyl.lawyer.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/user")

public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/add")
    public Object add(UserModel userModel){
        userService.add(userModel);
        return CommonResult.success(null);
    }
    @PostMapping("/changeEnable")
    public Object changeEnable(Integer id){
        userService.changeEnable(id);
        return CommonResult.success(null);
    }
    @PostMapping("/del")
    public Object del(Integer id){
        userService.delete(id);
        return CommonResult.success(null);
    }
    @PostMapping("/edit_info")
    public Object edit(UserModel userModel){
        String result = userService.changeInfo(userModel);
        return CommonResult.success(result);
    }
    @GetMapping("/findAll")
    public Object findAll(UserModel userModel){
        List<UserModel> all = userService.findAll(userModel);
        Map map = new HashMap();
        map.put("count",userService.getCount(userModel));
        map.put("list",all);
        return CommonResult.success(map);
    }
    @PostMapping("/findInfo")
    public Object findById(Integer id){
        UserModel byId = userService.findById(id);
        return CommonResult.success(byId);
    }
    @GetMapping("/count")
    public Object count(UserModel userModel){

        return CommonResult.success(userService.getCount(userModel));
    }


}
